<?php
namespace Admin\Controller;
use Think\Controller;
class PushController extends CommonController {

	//云推送列表
    public function pushList(){

        C('TOKEN_ON',false);
        
        $map=I("get.");

        if($map["secuname"]){
            $where["cloud_user.username"]=array("like","%".$map["secuname"]."%");
        }
        if($map["secstatus"]){
            $where["cloud_push_order.is_apply"]=$map["secstatus"];
        }

        $pushModel=D("pushOrder");

        $comList= $pushModel->getPushList($where);
       
        $this->assign("pushList",$comList["comList"]);
        $this->assign("page",$comList["page"]);

        $status=getPushStatus();
        $this->assign("apply_status",$status["apply"]);
        $this->assign("ok_status",$status["ok"]);

        $this->display();
    }
    //云推送详情
    public function pushDetails(){

        $id=I("get.id");

        if($id>0){

            $push=D("pushOrder")->getPushById($id);
        
            $this->assign("push",$push);
            $this->display();
        }else{
            $this->error("参数错误");
        }
    }
    //上传反馈文件
    public function upFeedbackForm(){

        $pushModel=D("pushOrder");
        $res=$pushModel->upPushFeedback($_FILES,$_POST);
      
        if($res){
            $this->success();
        }else{
            $this->error($pushModel->getError(),$_SERVER['HTTP_REFERER']);
        }
    }
   
    //ajax审核云推送
    public function ajaxChangePush(){

        $map=I("post.");

        $arr['code'] = 100;
        $arr['info'] = "操作失败";

        if(IS_AJAX && $map) {
            
            $res=D("pushOrder")->changeData($map);
            if($res){
                $arr['code'] = 200;
                $arr['info'] = "操作成功";
            }
        };
        $this->ajaxReturn($arr);

    }
    //添加、修改云推送套餐
    public function editPackage(){

        $id=I("get.id");

        if($id > 0){
            $package=D("pushPackage")->getPackageById($id);
            $this->assign("package",$package);   
        }

        $this->display();
    }
    //添加、修改云推送套餐表单
    public function editPackageForm(){

        $data=I("post.");

        $packageModel=D("pushPackage");
        $res=$packageModel->editData($data);

        if($res){
            $this->success();
        }else{
            $this->error($packageModel->getError(),$_SERVER['HTTP_REFERER']);
        }

    }
    //云推送套餐
    public function pushPackage(){

        $map=I("get.");
        if($map["sectitle"]){
            $where["title"]=array("like","%".$map["sectitle"]."%");
        }
        $comList=D("pushPackage")->getPushPackageList($where);
        
        $this->assign("comList",$comList["comList"]);
        $this->assign("page",$comList["page"]);

        $this->display();
    }

    //ajax删除套餐
    public function ajaxDelPackage(){

        $map=I("post.ids");

        $arr['code'] = 100;
        $arr['info'] = "删除失败";

        if(IS_AJAX && $map) {
            
            //拆分id
            $data=explode(",",$map);

            $packageModel=D("pushPackage");
            $res=$packageModel->delData($data);

            if($res>0){
                $arr['code'] = 200;
                $arr['info'] = "删除成功";
            }
        };
        $this->ajaxReturn($arr);

    } 
}